package org.example.sportdemo.controller;

import org.example.sportdemo.entity.Carousel;
import org.example.sportdemo.entity.Competition;
import org.example.sportdemo.service.CarouselService;
import org.example.sportdemo.service.CompetitionService;
import org.example.sportdemo.utils.PageUtils;
import org.example.sportdemo.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/carousel")
public class CarouselController {

    @Autowired
    private CarouselService carouselService;

    //分页
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params){

        PageUtils page = carouselService.queryPage(params);

        R r = new R();
        r.put("page",page);
        return r;
    }

    @RequestMapping("/selectAll")
    public R selectAll(@RequestParam Map<String, Object> params){

        List<Carousel> carouselList = carouselService.selectAll();

        R r = new R();
        r.put("carouselList",carouselList);
        return r;
    }

    //新增
    @RequestMapping(value = "/addCarousel")
    public R addCarousel(@RequestBody Carousel carousel){
        System.out.println(carousel);
        carouselService.addCarousel(carousel);
        return R.ok().put("carousel",carousel);
    }

    //修改
    @RequestMapping(value = "/updateCarousel")
    public R updateCarousel(@RequestBody Carousel carousel){
        System.out.println(carousel);
        carouselService.updateCarousel(carousel);
        return R.ok().put("carousel",carousel);
    }


    //根据id查询
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        Carousel carousel = carouselService.selectById(id);
        return R.ok().put("carousel",carousel);
    }

    //删除
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        carouselService.deleteByIds(ids);
        return R.ok();
    }

}
